package com.axend.aerosense.common.bean;

import android.text.TextUtils;

import com.axend.aerosense.base.app.BaseApplication;
import com.axend.aerosense.common.BuildConfig;
import com.axend.aerosense.common.R;
import com.axend.aerosense.common.UrlApi;
import com.blankj.utilcode.util.LogUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 房间设置功能枚举
 */
public enum FunctionRoomEnum {

    //卧床不起
    OVERSLEEPING_ALERT(
            "卧床不起",
            R.string.room_sleep_timeout,
            R.string.room_sleep_timeout_tips,
            0,
            R.string.room_sleep_timeout_about,
            1,
            new VipSettingTime(1, 60, 360, 180, 30),
            null,
            UrlApi.URL.SetSleepOvertime.getUrl()
    ),

    //频繁起夜
    FREQUENT_NIGHT_ACTIVITY(
            "频繁起夜",
            R.string.room_night_up_analysis,
            R.string.room_night_up_analysis_tips,
            0,
            R.string.room_night_up_analysis_about,
            2,
            null,
            new VipSettingTime(3, 1, 10, 3, 1),
            UrlApi.URL.SetNightRise.getUrl()
    ),

    //起夜未归
    WANDERING_ALERT_NIGHT(
            "离床未归",
            R.string.room_night_no_back,
            R.string.room_night_no_back_tips,
            0,
            R.string.room_night_no_back_about,
            3,
            new VipSettingTime(1, 30, 720, 360, 30),
            new VipSettingTime(1, 30, 720, 30, 30),
            UrlApi.URL.SetNightRiseNoReturn.getUrl()
    ),

    //外出未归
    WANDERING_ALERT_DAY(
            "外出未归",
            R.string.room_out_no_back,
            R.string.room_out_no_back_tips,
            0,
            R.string.room_out_no_back_about,
            3,
            new VipSettingTime(1, 60, 1440, 720, 60),
            new VipSettingTime(1, 60, 1440, 360, 60),
            UrlApi.URL.SetEgressNoReturn.getUrl()
    ),

    //久坐提醒
    SEDENTARY_NOTIFICATION(
            "久坐提醒",
            R.string.room_sedentary_analysis,
            R.string.room_sedentary_analysis_tips,
            R.string.room_sedentary_analysis_tips2,
            R.string.room_sedentary_analysis_about,
            4,
            new VipSettingTime(1, 60, 720, 180, 30),    //连续久坐
            new VipSettingTime(1, 60, 720, 360, 30),    //累计久坐
            null
    ),

    //作息异常
    BEDTIME_NOTIFICATION(
            "作息异常（熬夜提醒）",
            R.string.room_regular_lifestyle,
            R.string.room_regular_lifestyle_tips,
            0,
            R.string.room_regular_lifestyle_about,
            2,
            null,
            new VipSettingTime(2, 1260, 1440, 1380, 30),
            UrlApi.URL.SetWorkAndrest.getUrl()
    ),

    //原地静止
    MOTIONLESS_ALERT(
            "原地静止",
            R.string.room_motionless_alert,
            R.string.room_standing_still_tips,
            0,
            R.string.room_motionless_alert_about,
            3,
            new VipSettingTime(1, 30, 720, 120, 30),
            new VipSettingTime(1, 30, 720, 120, 30),
            UrlApi.URL.SetPositionStatic.getUrl()
    ),

    //异常进餐
    NUTRITION_ALERT(
            "异常进餐",
            R.string.room_meal_analysis,
            R.string.room_meal_analysis_tips,
            0,
            R.string.room_meal_analysis_about,
            0,
            null,
            null,
            UrlApi.URL.SetHaveMeals.getUrl()
    ),

    //卫浴滞留
    EXTENDED_TOILETING_ALERT(
            "卫浴滞留",
            R.string.room_bathroom_detention,
            R.string.room_bathroom_detention_tips,
            0,
            R.string.room_bathroom_detention_about,
            3,
            new VipSettingTime(0, 5, 120, 60, 5),
            new VipSettingTime(0, 5, 120, 45, 5),
            UrlApi.URL.SetToiletStop.getUrl()
    ),

    //频繁如厕
    FREQUENT_TOILETING_AT_NIGHT(
            "频繁如厕",
            R.string.room_bathroom_use_analysis,
            R.string.room_bathroom_use_analysis_tips,
            0,
            R.string.room_bathroom_use_analysis_about,
            2,
            null,
            new VipSettingTime(3, 1, 10, 3, 1),
            UrlApi.URL.SetToiletAnalysis.getUrl()
    ),

    //心跳/呼吸骤停告警
    NO_VITAL_SIGNALS(
            "心跳/呼吸骤停告警",
            R.string.room_no_vital_signals,
            R.string.room_no_vital_signals_tips,
            0,
            R.string.room_no_vital_signals_about,
            0,
            null,
            null,
            UrlApi.URL.SetNoVitalSignals.getUrl()
    ),

    //离床告警
    BED_EXIT_WARNING(
            "离床告警",
            R.string.room_bed_exit_warning,
            R.string.room_bed_exit_warning_tips,
            0,
            R.string.room_bed_exit_warning_about,
            0,
            null,
            null,
            UrlApi.URL.SetBedExitWarning.getUrl()
    ),

    //作息异常
    ABNORMAL_SLEEP(
            "作息异常",
            R.string.room_abnormal_sleep,
            R.string.room_abnormal_sleep_tips,
            0,
            R.string.room_abnormal_sleep_about,
            0,
            null,
            null,
            UrlApi.URL.SetAbnormalSleep.getUrl()
    ),

    //行动能力分析
    MOBILITY_ANALYSIS(
            "行动能力分析",
            R.string.room_trend_analysis,
            R.string.room_trend_analysis_tips,
            0,
            R.string.room_trend_analysis_about,
            0,
            null,
            null,
            UrlApi.URL.SetTrendAnalysis.getUrl()
    ),

    //坐起告警
    SIT_UP_ALERT(
            "坐起告警",
            R.string.room_sit_up_alert,
            R.string.room_sit_up_alert_tips,
            0,
            R.string.room_sit_up_alert_tips_about,
            0,
            null,
            null,
            ""  //TODO 坐起警告设置服务器地址
    ),

    //离家模式
    SURVEILLANCE_MODE(
            "离家模式",
            R.string.room_leave_mode,
            0,
            0,
            0,
            0,
            null,
            null,
            UrlApi.URL.UpdateLeaveHome.getUrl()
    ),

    //摔倒报警
    FALL_ALERT(
            "摔倒报警",
            R.string.room_fall_alert,
            0,
            0,
            0,
            0,
            null,
            null,
            ""  //TODO 摔倒报警服务器API接口
    ),
    ;

    //中文名字
    private String chineseName;
    //功能名字字符串资源
    private int nameRes;
    //功能设置说明1字符串资源
    private int firstTipsRes;
    //功能设置说明2字符串资源
    private int secondTipsRes;
    //功能的详细说明字符串资源
    private int aboutTipsRes;
    /**
     * 设置类型
     * 0：功能开关
     * 1：功能开关、Alert
     * 2：功能开关、Notification
     * 3：功能开关、Alert、Notification
     * 4：功能开关 ×2、Notification ×2
     */
    private int settingType;
    //报警设置
    private VipSettingTime alertSetting;
    //提醒设置
    private VipSettingTime notificationSetting;
    //提交设置数据的服务器接口
    private String serverApi;

    private static Map<String, FunctionRoomEnum> map;
    static {
        map = new HashMap<>();
        for (FunctionRoomEnum functionEnum : values()) {
            map.put(functionEnum.getName(), functionEnum);
        }
    }


    FunctionRoomEnum(String chineseName ,int nameRes,
                     int firstTipsRes, int secondTipsRes,
                     int aboutTipsRes, int settingType,
                     VipSettingTime alertSetting, VipSettingTime notificationSetting,
                     String serverApi) {

        this.chineseName = chineseName;
        this.nameRes = nameRes;
        this.firstTipsRes = firstTipsRes;
        this.secondTipsRes = secondTipsRes;
        this.aboutTipsRes = aboutTipsRes;
        this.settingType = settingType;
        this.alertSetting = alertSetting;
        this.notificationSetting = notificationSetting;
        this.serverApi = serverApi;
    }

    public String getChineseName(){
        return BuildConfig.DEBUG ? chineseName : "";
    }

    public int getNameRes() {
        return nameRes;
    }

    public String getName(){
        return getString(nameRes);
    }

    public int getFirstTipsRes() {
        return firstTipsRes;
    }

    public String getFirstTips(){
        return getString(firstTipsRes);
    }

    public int getSecondTipsRes() {
        return secondTipsRes;
    }

    public String getSecondTips(){
        return getString(secondTipsRes);
    }

    public int getAboutTipsRes() {
        return aboutTipsRes;
    }

    public String getAboutTips(){
        return getString(aboutTipsRes);
    }

    public int getSettingType() {
        return settingType;
    }

    public VipSettingTime getAlertSetting() {
        return alertSetting;
    }

    public VipSettingTime getNotificationSetting() {
        return notificationSetting;
    }

    public String getServerApi() {
        return serverApi;
    }

    private String getString(int strRes){
        return BaseApplication.getInstance().getString(strRes);
    }

    /**
     * 通过名字获取枚举
     * @param name
     * @return
     */
    public static FunctionRoomEnum getVipFunction(String name){
        if (TextUtils.isEmpty(name)) {
            LogUtils.d("name is null");
            return null;
        }

        return map.get(name);
    }

    @Override
    public String toString() {
        return "FunctionRoomEnum{" +
                "chineseName='" + chineseName + '\'' +
                ", nameRes=" + getName() +
                '}';
    }
}
